var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var extractTextPlugin = require('extract-text-webpack-plugin');
var CompressionWebpackPlugin = require('compression-webpack-plugin');

module.exports = {  
  devtool: 'inline-source-map',
  entry:{'bundle':'./entry/route.js',
  		 'Gocom2':'./entry/Gocom2.js',
  },
  output: {  
    path: __dirname + "/public",//打包后的文件存放的地方  
    filename: "[name].js"//打包后输出文件的文件名  
  },
  module: {//在配置文件里添加JSON loader  
      rules: [
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {//具体的编译的类型，
                presets: ['env','es2015', 'react'],//我们需要编译的是es6和react
                plugins: [
      				    ["import", { libraryName: "antd", style: "css" }] // `style: true` 会加载 less 文件
      				  ],
            }
        }
      },
      {
		    test: /\.css$/,
		     loader:  extractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' })
		},
      {
        test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
        loader: 'url-loader',
        options: {
          limit: 10000
        }
      }
    ]  
  },
  externals:{
        'require':'aliyun-sdk.min.js',
        // 'jquery': 'jquery',
        'JavascriptInterface':'window.JavascriptInterface'
    },
  plugins: [  
    new HtmlWebpackPlugin({
    	filename: __dirname+'/public/problem/index.html',  
	    template: "entry/index.tmpl.htm",
	    inject:'body',
	    hash:true,
	    chunks:['bundle']
    }),
     new HtmlWebpackPlugin({
            filename: __dirname+'/public/aa/Gocom2.html',
            template:"/entry/index.tmpl-2.htm",
            inject:'body',
            hash:true,
            chunks:['Gocom2']   // 这个模板对应上面那个节点
        }),
      // new CopyWebpackPlugin([
      //       {
      //           from: 'app/aliyun-sdk.min.js',
      //           to:'./'
      //       },
      //       {
      //           from: 'public/bundle.js',
      //           to:'./problem'
      //       },
      //       {
      //           from: 'public/bundle.css',
      //           to:'./problem'
      //       }

      //   ], {
      //       ignore: [],
      //       copyUnmodified: true,
      //       debug:"debug"
      //   } ),

    //压缩代码
	//new webpack.optimize.UglifyJsPlugin(),

  // new CompressionWebpackPlugin({ //gzip 压缩
  //       asset: '[path].gz[query]',
  //       algorithm: 'gzip',
  //       test: new RegExp(
  //           '\\.(js|css)$'    //压缩 js 与 css
  //       ),
  //       threshold: 1024,
  //       minRatio: 0.8
  //   }),
	
	 // css抽取
    new extractTextPlugin("[name].css"),

     new webpack.DllReferencePlugin({
            context: __dirname,
            manifest: require('./manifest.json'),
        }),
	
  ],  

}
